Zepto(function($) {
  /**
   * 保存
   */
  $(".save-address").click(function () {
    var data = {
      "name": $("#name").val(),
      "mobile": $("#mobile").val(),
      "region": $("#region").val(),
      "detailed": $("#detailed").val(),
      "used": "0"
    };
    addAddress(data);
  });
  /**
   * 设为默认地址
   */
  $(".sub-bottom").on("click",".create-name",function () {
    var data = {
      "name": $("#name").val(),
      "mobile": $("#mobile").val(),
      "region": $("#region").val(),
      "detailed": $("#detailed").val(),
      "used": "1"
    };
    addAddress(data);
  });
  function checkInput() {
    var mobileRegexp = /^(13[0-9]|15[012356789]|17[678]|18[0-9]|14[57])[0-9]{8}$/;
    if("" == $("#name").val() || $("#name").val() == null) {
      mui.toast("请输入收货人名字！");
      return false;
    }
    if("" == $("#mobile").val() || $("#mobile").val() == null) {
      mui.toast("请输入手机号！");
      return false;
    }
    if(!mobileRegexp.test($("#mobile").val())) {
        mui.toast("请输入正确手机号！");
        return false;
    }
    if("" == $("#region").val() || $("#region").val() == null) {
      mui.toast("请选择地区！");
      return false;
    }
    if("" == $("#detailed").val() || $("#detailed").val() == null) {
      mui.toast("请输入详细地址！");
      return false;
    }
    return true;
  }
  function addAddress(data) {
    var checke = checkInput();
    if(!checke){
      return
    }
    $.ajax({
      type: 'POST',
      url: getUrl + '/wxmall/member/address/insert',
      data: JSON.stringify(data),
      dataType: 'json',
      timeout: 15000,
      headers: headers("memberAddress.insert"),
      contentType:'application/json',
      success: function(data){
        collbackInit(data);
      },
      error: function(xhr, type){
      }
    });
  }
  function collbackInit(data) {
    if(data.success){
      mui.toast("添加地址成功！");
      window.location.href = document.referrer;
    }else{
      console.log("aaaaa");
      mui.toast("添加地址失败！");
    }
  }
  $(".cart-nogoods").on("click",".nogoods-find-btn",function () {
    window.location.href = "/index/index.html"
  })
  $(".nav-header").on("click",".nav-edit",function () {
    window.history.go(-1);
  })
  $(".list-down").on("click",".checkbox-cell",function () {
    var array = $("ul").find("input");
    array.forEach(function (item,index,array) {
      item.checked = false;
    });
    $(this).find("input")[0].checked = true;
    $(this).css("color","#00c4d2");
  });
});